package com.example.demo;

public class HelloThread extends Thread {

    public HelloThread() {
        super();
    }
    public HelloThread(String name) {
        super(name);
    }

    @Override
    //run()用来包含那些被线程执行的代码。
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"  :"+i);
        }
    }

    public static void main(String[] args) {
        HelloThread my1 = new HelloThread();
        HelloThread my2 = new HelloThread();
        //设置线程名称
        my1.setName("my1");
        my2.setName("my2");

        my1.start();
        my2.start();
        //打印当前线程名字
        System.out.println(Thread.currentThread().getName());
    }
}
